package com.butterfly.demo.daoImpl;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.stereotype.Component;

import com.butterfly.demo.dao.StudentDao;
import com.butterfly.demo.model.Student;
import com.opensymphony.xwork2.inject.ContainerBuilder;
@Component
public class StudentDaoImpl  implements StudentDao {
	HibernateTemplate hibernateTemplate; 
	public void save(Student student) {
		this.getHibernateTemplate().save(student);
	}
	
	public HibernateTemplate getHibernateTemplate() {
		return hibernateTemplate;
	}
	@Resource
	public void setHibernateTemplate(HibernateTemplate hibernateTemplate) {
		this.hibernateTemplate = hibernateTemplate;
	}

	public Student checkUser(Student student) {
		
		Object[] strList = {student.getUsername()};
		List<Student> studentList = new ArrayList<Student>();
		
		studentList = hibernateTemplate.find("from Student s where s.username = ?",strList);
		if(studentList.size()>0){
			return studentList.get(0);
		}else{
			return null;
		}
	}
	
}
